package com.qf.boot2203;

import com.qf.boot2203.config.Car;
import com.qf.boot2203.service.TestService;
import com.qf.boot2203.service.impl.TestServiceImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableConfigurationProperties(Car.class)
public class Boot2203Application {

    public static void main(String[] args) {

        // 获取springboot 创建的 IOC容器
        final ConfigurableApplicationContext context = SpringApplication.run(Boot2203Application.class, args);

        final TestService tsb = (TestService) context.getBean("tsb");

        System.out.println(tsb.hello());

//        final TestService testServiceImpl1 = (TestService) context.getBean("testServiceImpl");
//        final TestService testServiceImpl2 = (TestService) context.getBean("testServiceBetter");
//        final TestService testServiceImpl3 = (TestService) context.getBean("testServiceBetter");
//
//        System.out.println(testServiceImpl2==testServiceImpl3); // 默认bean是单例的
//
//        System.out.println(testServiceImpl1.hello());
//        System.out.println(testServiceImpl2.hello());
    }

    @Bean("ts")
    public TestService testService(){
        final TestServiceImpl testService = new TestServiceImpl();
        return testService;
    }

}
